let x=0;
let y=0;
export default {
    updated(el,binding){
        let canMove = binding.value
        if(!canMove){
            el.style.cursor = 'none'
            el.style.position = 'absolute'
            el.style.left = 0 +'px'
            el.style.top = 0 +'px'
        }else{
            el.style.cursor = 'move'
            el.style.position = 'absolute'
            el.style.userSelect = 'none';
            el.style.left = x +'px'
            el.style.top = y +'px'
            el.ontouchstart = function (e) {
            let disx = e.pageX - el.offsetLeft
            let disy = e.pageY - el.offsetTop
            let maxX = document.body.clientWidth - parseInt(window.getComputedStyle(el).width)
            let maxY = document.body.clientHeight - parseInt(window.getComputedStyle(el).height)
            document.ontouchmove = function (e) {
                 x = e.pageX - disx
                 y = e.pageY - disy
               
                if (x < 0) {
                    x = 0
                } else if (x > maxX) {
                    x = maxX
                }

                if (y < 0) {
                    y = 0
                } else if (y > maxY) {
                    y = maxY
                }
                
                el.style.left = x + 'px'
                el.style.top = y + 'px'
            }
            document.ontouchend = function () {
                if(x > maxX/2){
                    x = maxX
                    el.style.left = x + 'px';
                }else{
                    x = 0;
                    el.style.left = x + 'px';
                }
                el.style.top = y + 'px'
                document.ontouchmove = document.ontouchend = null
            }
        }
        }
    }
}